next up previous contents index
Next: Blocks Up: Programsunits, blocks Previous: Programs

Units

A unit contains a set of declarations, procedures and functions that can be used by a program or another unit.

The syntax for a unit is as follows:


Units

syntdiag4592

syntdiag4596

syntdiag4600

syntdiag4604

syntdiag4608

syntdiag4612

The interface part declares all identifiers that must be exported from the unit. This can be constant, type or variable identifiers, and also procedure or function identifier declarations. Declarations inside the implementationpart are not accessible outside the unit. The implementation must contain a function declaration for each function or procedure that is declared in the interface part. If a function is declared in the interface part, but no declaration of that function is present in the implementation section is present, then the compiler will give an error.

When a program uses a unit (say unitA) and this units uses a second unit, say unitB, then the program depends indirectly also on unitB. This means that the compiler must have access to unitB when trying to compile the program. If the unit is not present at compile time, an error occurs.

Note that the identifiers from a unit on which a program depends indirectly, are not accessible to the program. To have access to the identifiers of a unit, you must put that unit in the uses clause of the program or unit where you want to yuse the identifier.

Units can be mutually dependent, that is, they can reference each other in their uses clauses. This is allowed, on the condition that at least one of the references is in the implementation section of the unit. This also holds for indirect mutually dependent units.

If it is possible to start from one interface uses clause of a unit, and to return there via uses clauses of interfaces only, then there is circular unit dependence, and the compiler will generate an error.

As and example : the following is not allowed:
listing4564
But this is allowed :
listing4566
Because UnitB uses UnitA only in it's implentation section.

In general, it is a bad idea to have circular unit dependencies, even if it is only in implementation sections.


next up previous contents index
Next: Blocks Up: Programsunits, blocks Previous: Programs

Michael Van Canneyt
Fri Sep 25 09:15:40 MEST 1998